
import { registerClass } from "../../../cfw/tools/class_decorator";
import BaseAd from "../../core/base/BaseAd";
import { NativeRewardedVideoAd } from "../../native/native";
import { ResultState } from "../../SDKDefine";
;


@registerClass('MiMoRewardAd')
export default class MiMoRewardAd extends BaseAd {

    protected ad: NativeRewardedVideoAd;
    hide(): void {
    }
    load(): void {
        if (this.ad) {
            this.ad.load();
        }
    }
    show() {
        if (this.ad) {
            this.ad.show()
        }
    }

    create() {
        console.log('NativeTest MiMoRewardAd create  ', this.adUnitID)
        if (!this.ad) {
            this.ad = this.sdk.createRewardedVideoAd({
                adUnitId: this.adUnitID
            })
            this.ad.onLoad(this.getFunc(this.onLoad))
            this.ad.onError(this.getFunc(this.onError))
            this.ad.onClose(this.getFunc(this.onClose))
            this.ad.load();
        } else {
            this.ad.load();
        }
    }

    onClose(res: any) {
        console.log('NativeTest onClose ', res)
        if (res && res.isEnded || res === undefined) {
            this.callResultCallback(ResultState.YES)
        } else {
            this.callResultCallback(ResultState.NO)
        }
    }

    destroy(): void {
        if (this.ad) {
            this.ad.offLoad(this.getFunc(this.onLoad))
            this.ad.offError(this.getFunc(this.onError))
            this.ad.offClose(this.getFunc(this.onClose))
            this.ad.destroy()
            this.ad = null;
        }
    }
}
